const isDevelopment = process.env.NODE_ENV === 'development';
const CompressionPlugin = require('compression-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  publicPath: isDevelopment ? '/' : '/screen/',
  outputDir: 'screen',
  assetsDir: 'statics',
  lintOnSave: isDevelopment ? true : false,
  productionSourceMap: isDevelopment ? true : false,
  configureWebpack: () => {
    if (!isDevelopment) {
      return {
        plugins: [
          new CompressionPlugin({
            test: /\.(js|css)$/,
            threshold: 10240, // 10k
            deleteOriginalAssets: false
          }),
          new UglifyJsPlugin({
            uglifyOptions: {
              compress: {
                // drop_debugger: true,
                // drop_console: true
              }
            },
            parallel: true
          }),
        ]
      };
    }
  },
  devServer: {
    port: 8088,
    https: false,
    proxy: {
      '/api': {
        target: '/',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}